package com.wikikii.bannerlib.banner.view;

import com.bumptech.glide.Glide;

import ohos.agp.components.*;
import ohos.app.Context;

import java.util.ArrayList;
import java.util.List;

/**
 * banner 背景容器
 */
public class BannerBgContainer extends DependentLayout {

    private List<BannerBgView> bannerBgViews = new ArrayList<>();

    /**
     * 构造函数
     *
     * @param context 上下文
     */
    public BannerBgContainer(Context context) {
        this(context, null);
    }

    /**
     * 构造函数
     *
     * @param context 上下文
     * @param attrs 属性
     */
    public BannerBgContainer(Context context, AttrSet attrs) {
        this(context, attrs, null);
    }

    /**
     * 构造函数
     *
     * @param context 上下文
     * @param attrs 属性
     * @param styleName 样式名称
     */
    public BannerBgContainer(Context context, AttrSet attrs, String styleName) {
        super(context, attrs, styleName);
    }

    public List<BannerBgView> getBannerBgViews() {
        return this.bannerBgViews;
    }

    /**
     * 设置
     *
     * @param context context
     * @param bgUrlList 背景图集合
     */
    public void setBannerBackBg(Context context, List<Object> bgUrlList) {
        bannerBgViews.clear();
        this.removeAllComponents();
        StackLayout.LayoutConfig layoutParams = new StackLayout.LayoutConfig(ComponentContainer.LayoutConfig.MATCH_PARENT, AttrHelper.vp2px(240, getContext()));
        for (Object urlImageView : bgUrlList) {
            BannerBgView bannerBgView = new BannerBgView(context);
            bannerBgView.setLayoutConfig(layoutParams);
            Glide.with(context).load(urlImageView).centerCrop().into(bannerBgView.getImageView());
            bannerBgViews.add(bannerBgView);
            this.addComponent(bannerBgView);
        }
        this.moveChildToFront(bannerBgViews.get(0));
    }
}
